package userimage;

import global.Sources;
import userimage.enumbar.EnumBar;

import javax.swing.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.io.FileNotFoundException;

import static global.ProjectData.*;

public class BadEditor extends JFrame implements ComponentListener {

    EnumBar eb = new EnumBar();
    IndiBar ib = new IndiBar();
    WorkArea wa = new WorkArea();

    public BadEditor() throws FileNotFoundException {
        super();
        init();

        addComponentListener(this);

        getContentPane().add(eb);
        getContentPane().add(ib);
        getContentPane().add(wa);
    }

    private void init() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(theme.WIDTH, theme.HEIGHT);
        setLocation(toolkit.getScreenSize().width / 2 - theme.WIDTH / 2, toolkit.getScreenSize().height / 2 - theme.HEIGHT / 2);
        setIconImage(new ImageIcon(Sources.ICON).getImage());
        if (projectDir.equals(""))
            setTitle("Bad Editor");
        else {
            String[] s = projectDir.split("/");
            setTitle(s[s.length - 1] + " - Bad Editor");
        }
        setLayout(null);
        setVisible(true);
        setFocusable(true);
    }

    @Override
    public void componentResized(ComponentEvent componentEvent) {
        eb.setSize(getWidth(), eb.getHeight());

        ib.setSize(getWidth(), ib.getHeight());
        ib.setLocation(0, getHeight() - contentPaneFixedHeightError - theme.indibar_height);

        wa.setSize(getWidth(), getHeight() - contentPaneFixedHeightError - theme.enumbar_height - theme.indibar_height);
    }

    @Override
    public void componentMoved(ComponentEvent componentEvent) {

    }

    @Override
    public void componentShown(ComponentEvent componentEvent) {

    }

    @Override
    public void componentHidden(ComponentEvent componentEvent) {

    }
}
